package com.tebiecloud.base.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.tebiecloud.base.client.model.StorefVo;
import com.tebiecloud.base.client.model.entity.BaseAccount;
import com.tebiecloud.base.server.mapper.BaseAccountMapper;
import com.tebiecloud.base.server.service.BaseAccountService;
import com.tebiecloud.common.mybatis.base.service.impl.BaseServiceImpl;
import com.tebiecloud.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 登录账号 服务实现类
 * @author tebie
 * @date 2019-08-01
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BaseAccountServiceImpl extends BaseServiceImpl<BaseAccountMapper, BaseAccount> implements BaseAccountService {

    @Autowired
    private BaseAccountMapper baseAccountMapper;

    /**
     * 获取账号信息
     * @param account
     * @param accountType
     * @param domain
     * @return
     */
    @Override
//    @Cacheable(value = "account", key = "'account:' + #account + ':' + #accountType + ':' + #domain")
    public BaseAccount getAccount(String account, String accountType, String domain) {
        QueryWrapper<BaseAccount> queryWrapper = new QueryWrapper();
        queryWrapper.eq("account", account);
        if(!StringUtils.isEmpty(accountType)) {
            queryWrapper.eq("account_type", accountType);
        }
        if(!StringUtils.isEmpty(domain)) {
            queryWrapper.eq("domain", domain);
        }
        return baseAccountMapper.selectOne(queryWrapper);
    }

    @Override
    public List<StorefVo> agm(Integer page, Integer limit) {
       return baseAccountMapper.agm(page,limit);
    }


}
